<?php
namespace Cyfy\Modules\News\Forms;

use \Cyfy\Message;
use \Cyfy\Modules\Forms;
use \Cyfy\Modules\News\Module as News;


class Settings extends Forms\Form
{
    function structure()
    {
        $this -> permission("News", "administration");
        $this -> stay = true;
        
        $i = new Forms\TextBox("perPage", self :: t(10));
        $i -> format = "number";
        $i -> maxValue = 100;
        $i -> required = true;
        $this -> addItem($i);
        
        $i = new Forms\TextBox("inBlock", self :: t(20));
        $i -> format = "number";
        $i -> maxValue = 50;
        
        $i -> required = true;
        $this -> addItem($i);

        $i = new Forms\TextBox("imageWidth", self :: t(30));
        $i -> format = "number";
        $i -> minValue = 10;
        $i -> maxValue = 500;
        $i -> required = true;
        $this -> addItem($i);
        
        $i = new Forms\TextBox("imageHeight", self :: t(40));
        $i -> format = "number";
        $i -> minValue = 10;
        $i -> maxValue = 500;
        $i -> required = true;
        $this -> addItem($i);
        
        $b = new Forms\Button(self :: t(50));
        $this -> addButton($b);
    }
    
    function submit()
    {
        
        foreach(News :: $settings as $d)
        {
           News :: define($d, $this->get($d));
        }
        
        // reload constants
        \Cyfy\Constants :: load();
        
        // after reloading constants
        News :: rebuildThumbnails();
        
        \Cyfy\Message :: set(self :: t(60));
        return true;
    }
}